<?php

/**
 * apparence actions.
 *
 * @package    sinc
 * @subpackage apparence
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class apparenceActions extends sfActions
{


 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
   $this->id_user = $this->getUser()->getGuardUser()->getId();

   $c = new Criteria();
   $c->add(PagePeer::ID_USER,$this->id_user);
   $this->css = PagePeer::doSelect($c);
  }

public function executeSubmit($request)
{
  $this->id = $this->getUser()->getGuardUser()->getId();

  $this->forward404Unless($request->isMethod('post'));
       //echo $request->getParameter('css');

     $c = new Criteria();
     $c->add(PagePeer::ID_USER,$this->id);
     $res = PagePeer::doSelect($c);

    if(isset($res[0])){
     foreach ($res as $re){
         $user = PagePeer::retrieveByPk($re->getIdPage());
     }
     $user->setIdUser($this->id);
     $user->setCss($request->getParameter('css'));
    }
    else{
     $user = new Page();
     $user->setIdUser($this->id);
     $user->setCss($request->getParameter('css'));
    }

     $this->form = new PageForm($user);
     $this->processForm($request, $this->form);

  //$this->setTemplate('new');
}

public function executeValidation()
{
}

protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $contient = $form->save();
      $this->redirect('agenda/index');
    }
  }

}

?>